package com.doyens.item.listerer;

import com.doyens.item.service.GoodsHtmlService;
import com.doyens.item.service.GoodsService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GoodsListener {

    @Autowired
    private GoodsHtmlService goodsService;

    //新增的监听
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "DOYENS.ITEM.SAVE.QUEUE",durable = "true"),
            exchange = @Exchange(value = "DOYENS.ITEM_EXCHANGE",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),
            key = {"item.insert","item.update"}
    ))
    public void save(Long id){
        if (id ==null){
            return;
        }
        this.goodsService.createHtml(id);
    }

    //删除的监听
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "DOYENS.ITEM.DELETE.QUEUE",durable = "true"),
            exchange = @Exchange(value = "DOYENS.ITEM_EXCHANGE",ignoreDeclarationExceptions = "true",type = ExchangeTypes.TOPIC),
            key = {"item.delete"}
    ))
    public void delete(Long id){
        if (id ==null){
            return;
        }
        this.goodsService.deleteHtml(id);
    }
}
